package com.yuncheng.spcyApi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.entity.SpcyJcyPrrymd;
import com.yuncheng.spcyApi.mapper.SpcyJcyPrrymdMapper;
import com.yuncheng.spcyApi.service.ISpcyJcyPrrymdService;
import com.yuncheng.spcyApi.utils.OrderItemUtils;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.yuncheng.common.base.service.impl.BaseServiceImpl;

/**
 * @Description: 检查员-聘任人员名单
 * @Author: yuncheng
 * @Date: 2024-01-16
 * @Version: V1.0
 */
@Service
public class SpcyJcyPrrymdServiceImpl extends BaseServiceImpl<SpcyJcyPrrymdMapper, SpcyJcyPrrymd> implements ISpcyJcyPrrymdService {

    @Override
    public Page<SpcyJcyPrrymd> pageList(SpcyJcyPrrymd query, String gjz, PageVo pageVo, OrderItemVo orderItemVo) {
        Page<SpcyJcyPrrymd> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        LambdaQueryWrapper<SpcyJcyPrrymd> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SpcyJcyPrrymd::getFprjbxxid, query.getId());
        queryWrapper.like(StringUtils.isNotBlank(query.getFsfzh()), SpcyJcyPrrymd::getFsfzh, query.getFsfzh());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFgzdw()), SpcyJcyPrrymd::getFgzdw, query.getFgzdw());
        queryWrapper.like(StringUtils.isNotBlank(query.getRealname()), SpcyJcyPrrymd::getRealname, query.getRealname());

        if (StringUtils.isNotBlank(gjz)){

            int selectSex = 3;
            if (gjz.contains("男")){
                selectSex = 1;
            }else if (gjz.contains("女")){
                selectSex = 2;
            }
            Integer finalSelectSex = selectSex;

            queryWrapper
                    .and(f->f.like(SpcyJcyPrrymd::getFgzdw, gjz)
                            .or()
                            .like(SpcyJcyPrrymd::getRealname, gjz)
                            .or()
                            .like(SpcyJcyPrrymd::getFsxzy, gjz)
                            .or()
                            .like(SpcyJcyPrrymd::getFxl, gjz)
                            .or()
                            .like(SpcyJcyPrrymd::getFjcyxl, gjz)
                            .or()
                            .eq(SpcyJcyPrrymd::getSex, finalSelectSex)
                    );
        }

        if (StringUtils.isBlank(orderItemVo.getOrderItem())){
            queryWrapper.orderByDesc(SpcyJcyPrrymd::getCreateTime);
        }else {
            OrderItemUtils.setOrderItem(queryWrapper, orderItemVo);
        }
        return page(page, queryWrapper);
    }
}
